//
//  KKAnimationTableViewController.m
//  KKAnimation
//
//  Created by Mac mini on 16/2/2.
//  Copyright © 2016年 JuniorCodingPerson. All rights reserved.
//

#import "KKAnimationTableViewController.h"

#import "AppDelegate.h"

@interface KKAnimationTableViewController () {
    
    NSArray *_kk_animationItems;
}

@end

@implementation KKAnimationTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor greenColor];
    
    _kk_animationItems = @[@"淡入淡出",@"推挤(由上往下)",@"推挤(由左往右)",@"移动(由上往下)",@"移动(由左往右)",@"揭开(由上往下)",@"揭开(由左往右)",@"向上翻页",@"向下翻页",@"水滴效果",@"收缩",@"立体翻转(由上往下)",@"立体翻转(由左往右)",@"翻转(由上往下)",@"翻转(由左往右)"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _kk_animationItems.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"kkAnimationCellIdentifier" forIndexPath:indexPath];
    
    cell.textLabel.text = _kk_animationItems[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CATransition *transition = [CATransition animation];
    
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    delegate.portrait = indexPath.row %2 == 0 ? true : false;
    
    switch (indexPath.row) {
        case 0:
        {
            transition.type = kCATransitionFade;
        }
            break;
        case 1:
        {
            transition.type = kCATransitionPush;
            transition.subtype = kCATransitionFromBottom;
        }
            break;
        case 2:
        {
            transition.type = kCATransitionPush;
            transition.subtype = kCATransitionFromLeft;
        }
            break;
        case 3:
        {
            transition.type = kCATransitionMoveIn;
            transition.subtype = kCATransitionFromBottom;
        }
            break;
        case 4:
        {
            transition.type = kCATransitionMoveIn;
            transition.subtype = kCATransitionFromLeft;
        }
            break;
        case 5:
        {
            transition.type = kCATransitionReveal;
            transition.subtype = kCATransitionFromBottom;
        }
            break;
        case 6:
        {
            transition.type = kCATransitionReveal;
            transition.subtype = kCATransitionFromLeft;
        }
            break;
        case 7:
        {
            transition.type = @"pageCurl";
            transition.subtype = kCATransitionFromLeft;
        }
            break;
        case 8:
        {
            transition.type = @"pageUnCurl";
            transition.subtype = kCATransitionFromLeft;
        }
            break;
        case 9:
        {
            transition.type = @"rippleEffect";
        }
            break;
        case 10:
        {
            transition.type = @"suckEffect";
        }
            break;
        case 11:
        {
            transition.type = @"cube";
            transition.subtype = kCATransitionFromBottom;
        }
            break;
        case 12:
        {
            transition.type = @"cube";
            transition.subtype = kCATransitionFromLeft;
        }
            break;
        case 13:
        {
            transition.type = @"oglFlip";
            transition.subtype = kCATransitionFromBottom;
        }
            break;
        case 14:
        {
            transition.type = @"oglFlip";
            transition.subtype = kCATransitionFromLeft;
        }
            break;

        default:
            break;
    }
    
    transition.duration = 1.0;
    [self.navigationController.view.layer addAnimation: transition forKey: @""];
    
}


@end
